package com.example.demo.controller;

import com.example.demo.server.WebSocket;
import com.example.demo.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MyTestController {

    @Autowired
    private WebSocket webSocket;

    @Autowired
    TestService testService;

    @RequestMapping("/test_conn")
    public void test_conn(){
        //要从后端页面发送消息
        try {
            Thread.sleep(3000);
            //给前端发送消息
            webSocket.sendMessage("客户端你好，这是服务端发送的消息");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @RequestMapping("/call")
    public void call(){
       testService.callTalk();

    }


}
